package com.zx.cloud.config;

import java.util.LinkedList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.zx.cloud.config.SwaggerTemplate;
import com.zx.cloud.controller.StatusCode;
import com.zx.cloud.model.swagger.SwaggerApiInfo;

import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author Alex
 */
@EnableSwagger2
@Configuration
public class SwaggerConfiguration extends SwaggerTemplate {

    @Bean
    public SwaggerApiInfo info() {
    	SwaggerApiInfo swaggerApiInfo=new SwaggerApiInfo();
    	swaggerApiInfo.setTitle("application-quartz");
    	swaggerApiInfo.setStatusList(extractStatusCodes());
    	swaggerApiInfo.setVersion("v1");
        return swaggerApiInfo;
    }

    private List<ResponseMessage> extractStatusCodes() {
        final LinkedList<ResponseMessage> list = new LinkedList<>();
        for (StatusCode statusCodes : StatusCode.values()) {
            final ResponseMessageBuilder builder = new ResponseMessageBuilder();
            final ResponseMessage message = builder
                    .code(statusCodes.code())
                    .message(statusCodes.message())
                    .build();
            list.add(message);
        }
        return list;
    }

}
